package com.qf.controller;

import com.qf.SelfClass.ResponseData1;
import com.qf.pojo.User;
import com.qf.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author Mr.Liu
 * @date 2021/12/14 22:37
 */
@RequestMapping("/user")
@Controller
public class UserController {
    @Autowired
    private UserService userService;
    @RequestMapping("/findAll")
    public void findAll(){
        List<User> user = userService.findAllUser();
        for (User us : user){
            System.out.println(us);
        }
    }
    @ResponseBody
    @RequestMapping("/login")
    public ResponseData1 login(HttpServletRequest request){
        String tel = request.getParameter("tel");
        String password = request.getParameter("password");
        User user = userService.findUser(tel,password);
        //System.out.println(user);
        if (user!=null){
            request.getSession().setAttribute("user",user);
            return new ResponseData1(1,"登录成功");
        }
        return new ResponseData1(0,"用户名或密码错误");
    }
}
